﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.DDD.Controllers
{
    public class users:Controller
    {
        public void show(int p)
        {
            var con = Models.Common.OpenConnection();
            //创建Page对象
            NFinal.Page pg = new NFinal.Page(p, 5);
            //计算URL所用到的函数
            pg.GetUrlFunction = (pi) => { return Url.DDD_users_show(pi); };
            //分页语句获取分页对象
            var us = con.Page("select * from users",pg);
            con.Close();
            this.View("show.aspx");
        }
        [GetJson("users/edit.aspx")]
        public void edit(Models.Entity.Common.users user)
        {
            var con = Models.Common.OpenConnection();
            var count = con.Update("users",user);
            con.Close();
            this.AjaxReturn(count > 0);
        }
        [GetJson("users/show.aspx")]
        public void insert(Models.Entity.Common.users user)
        {
            var con = Models.Common.OpenConnection();
            var count = con.Insert("users",user);
            con.Close();
            this.AjaxReturn(count > 0);
        }

        public void delete(int id)
        {
            var con = Models.Common.OpenConnection();
            var count = con.Delete("delete from users where id=@id");
            con.Close();
            this.AjaxReturn(count > 0);
        }
    }
}